package com.controller.message;

import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.po.MessageInfo;
import com.service.message.MessageService;
import com.util.UUIDGenerator;

@Controller
@RequestMapping("/jsp/message")
public class MessageController {
    @Resource(name = "messageServiceImp")
    private MessageService messageService;

    @RequestMapping(value = "getMessageview")
    public String getMessageView(Model model, String zjid) {
	model.addAttribute("zjid", zjid);
	return "message/message";
    }

    @RequestMapping(value = "getQuestionview")
    public String getQuestionView() {

	return "message/myquestion";
    }

    @RequestMapping(value = "getSPMessageview")
    public String getSPMessageView() {

	return "infocenter/spmessage";
    }
    @RequestMapping(value = "getMessageCheckview")
    public String getSPMessageCheckView(Model model, HttpServletRequest request, HttpServletResponse resp,
		String message_id,String user_id,String touser_id) {
	
        model.addAttribute("message_id", message_id);
        model.addAttribute("user_id", user_id);
        model.addAttribute("touser_id", touser_id);
	return "infocenter/messagecheck";
    }
    // 计算留言数量
    @ResponseBody
    @RequestMapping(value = "/getMessageCount")
    public int getMessageCount(MessageInfo messageInfo) {
	int i = messageService.getMessageCount(messageInfo);
	return i;
    }

    // 获取留言列表
    @ResponseBody
    @RequestMapping(value = "/getMessageList")
    public List<MessageInfo> getMessageList(MessageInfo messageInfo) {
	List<MessageInfo> list = messageService.getMessageList(messageInfo);
	return list;
    }

    // 计算留言数量
    @ResponseBody
    @RequestMapping(value = "/getMessageCaCount")
    public int getMessageCaCount(MessageInfo messageInfo) {
	int i = messageService.getMessageCaCount(messageInfo);
	return i;
    }

    // 获取留言列表
    @ResponseBody
    @RequestMapping(value = "/getMessageCatalogue")
    public List<MessageInfo> getMessageCatalogue(MessageInfo messageInfo) {
	List<MessageInfo> list = messageService.getMessageCatalogue(messageInfo);
	return list;
    }
    
    // 删除留言
    @ResponseBody
    @RequestMapping(value = "/deleteMessage")
    public int deleteMessage(String id) {
	int i = messageService.deleteMessage(id);
	return i;
    }

    // 删除留言
    @ResponseBody
    @RequestMapping(value = "/illegalMessage")
    public int deleteillegalMessage(String id, String userid) {
	int i = messageService.deleteMessage(id);
	return i;
    }

    // 删除留言
    @ResponseBody
    @RequestMapping(value = "/waterMessage")
    public int deletewaterMessage(String id, String userid) {
	int i = messageService.deleteMessage(id);
	return i;
    }

    // 删除留言
    @ResponseBody
    @RequestMapping(value = "/addMessage")
    public int addMessage(MessageInfo messageInfo) {
	String id = UUIDGenerator.getUUID();
	messageInfo.setMessage_id(id);
	int i = messageService.addMessage(messageInfo);
	return i;
    }

    // 更新
    @ResponseBody
    @RequestMapping(value = "/updateMessage")
    public int updateMessage(String id) {
	int i = messageService.updateMessage(id);
	return i;
    }
    // 获取专家未回复留言条数
    @ResponseBody
    @RequestMapping(value = "/getMessageNoReply")
    public int getMessageNoReply(String userid) {
        MessageInfo messageInfo= new MessageInfo();
        messageInfo.setTouser_id(userid);
        messageInfo.setMessage_reply("未回复");
        messageInfo.setMessage_parentid("null");
        int no_reply=messageService.getMessageCount(messageInfo);
	return no_reply;
    }
}
